require 'test/unit'
require 'lib/smppclient/pdu/alert_notification'
require 'lib/smppclient/pdu/tlv/tag'
require 'lib/smppclient/pdu/tlv/ms_availability_status'

class TestAlertNotification < MiniTest::Unit::TestCase

  include SmppClient::Pdu
  include SmppClient::Pdu::Tlv
  include SmppClient::Util

  def test_bytes_to_object
    bb = ByteBuffer.new
    bb.append_int(49)
    bb.append_int(258)
    bb.append_int(0)
    bb.append_int(1000123456)
    bb.append_byte(0)
    bb.append_byte(0)
    bb.append_cstring('99501363400')
    bb.append_byte(2)
    bb.append_byte(1)
    bb.append_cstring('destination')
    bb.append_short(0x0422)
    bb.append_short(1)
    bb.append_byte(2)

    an = AlertNotification.new(bb)
    assert_equal(49, an.command_length)
    assert_equal(CommandId::ALERT_NOTIFICATION, an.command_id)
    assert_equal(CommandStatus::ESME_ROK, an.command_status)
    assert_equal(1000123456, an.sequence_number)
    assert_equal(0, an.source_addr_ton)
    assert_equal(0, an.source_addr_npi)
    assert_equal('99501363400', an.source_addr)
    assert_equal(2, an.esme_addr_ton)
    assert_equal(1, an.esme_addr_npi)
    assert_equal('destination', an.esme_addr)
    assert_equal(2, an.tlvs[Tag::MS_AVAILABILITY_STATUS].value)
  end

  def test_object_to_bytes
    an = AlertNotification.new
    an.command_status = CommandStatus::ESME_ROK
    an.sequence_number = 115
    an.source_addr_ton = Ton::INTERNATIONAL
    an.source_addr_npi = Npi::LAND_MOBILE
    an.source_addr = 'remarema'
    an.esme_addr_ton = Ton::UNKNOWN
    an.esme_addr_npi = Npi::WAP_CLIENT_ID
    an.esme_addr = 'destmy'
    an.tlvs[Tag::MS_AVAILABILITY_STATUS] = MsAvailabilityStatus.new(0)
    assert_equal('00000029000001020000000000000073010672656d6172656d61000012646573746d79000422000100', an.buffer.to_s)
  end

end